﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.SqlClient;

class MysqlManager
{
    string ip = "10.99.19.121";
    string username = "root";
    string password = "123456";

    string dbName = "haha";

    MySqlConnection connect;
    MySqlCommand cmd;

    public MysqlManager(int userId, string name)
    {
        string conSql = "server=" + ip + ";user id=" + username + ";password=" + password + ";database=" + dbName;
        connect = new MySqlConnection();
        connect.ConnectionString = conSql;
        cmd = connect.CreateCommand();
        connect.Open();

        //connect.Close();
    }

    //以下方法都很低俗，需根据自己需求更改成更方便的
    //可以根据自己数据库来修改成动态传参，比如 "insert into"+tb_name+ "values('"+value1+"','"+value2+"')";   
    //也可以通过 string.Format("insert into tb_name values ( '{0}','{1}','{2}','{3}','{4}')", value1, value2, value3, value4 ,value5);

    public void Insert(string sqlText)//这个可根据自己数据库来确定参数
    {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sqlText;

        cmd.ExecuteNonQuery();
    }
    public DataSet Select(string sqlText)
    {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sqlText;
        cmd.ExecuteNonQuery();

        DataSet dt = new DataSet();
        MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
        adapter.Fill(dt);
        return dt;
    }

    public void Delete(string sqlText)
    {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sqlText;
        cmd.ExecuteNonQuery();
    }

    public void updata(string sqlText)
    {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sqlText;
        cmd.ExecuteNonQuery();
    }
}
